/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;
import java.sql.*;
/**
 *
 * @author user
 */
public class ConecttoDatabase
{
     private static Connection con = null;
    private static String url = "jdbc:sqlserver://";
    private static String serverName= "localhost";
    private static String portNumber = "9999";
    private static String databaseName= "Project";

    private static String getConnectionUrl()
    {
        return url + serverName + ":" + portNumber + "; databaseName=" + databaseName + "; integratedSecurity=true";
    }

    public static Connection getConnection()
    {
          try
          {
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
               con = DriverManager.getConnection(getConnectionUrl());
          }
          catch(Exception e)
          {
              System.out.println(e);
              con = null;
          }
          return con;
     }
    
    public static void closeConnection()
    {
          try
          {
               if(con!=null)
                    con.close();
               con=null;
          }
          catch(Exception e)
          {
               e.printStackTrace();
          }
     }  
    
}
